//
//  SHPageControl.m
//  SohoNaru
//
//  Created by ladaka on 13. 8. 1..
//  Copyright (c) 2013년 __MyCompanyName__. All rights reserved.
//

#import "SHPageControl.h"

@interface SHPageControl (Private)
- (void) updateDots;
@end


@implementation SHPageControl

@synthesize imgNormal = _imgNormal;
@synthesize imgCurrent = _imgCurrent;


- (void) setCurrentPage:(NSInteger)currentPage
{
    [super setCurrentPage:currentPage];
    
    [self updateDots];
}

- (void) updateCurrentPageDisplay
{
    [super updateCurrentPageDisplay];
    
    [self updateDots];
}

- (void) setImgNormal:(UIImage*)image
{
    _imgNormal = image;
    
    [self updateDots];
}

- (void) setImgCurrent:(UIImage*)image
{
    _imgCurrent = image;
    
    [self updateDots];
}

- (void) endTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event 
{
    [super endTrackingWithTouch:touch withEvent:event];
    
    [self updateDots];
}

#pragma mark - (Private)

- (void) updateDots
{
    if(_imgCurrent || _imgNormal)
    {
        NSArray *dotViews = self.subviews;
        for(int i = 0; i < dotViews.count; ++i)
        {
            UIImageView* dot = [dotViews objectAtIndex:i];
            CGRect frame = dot.frame;
            frame.size.width = (i == self.currentPage) ? _imgCurrent.size.width / 2 : _imgNormal.size.width / 2;
            frame.size.height = (i == self.currentPage) ? _imgCurrent.size.height / 2 : _imgNormal.size.height / 2;
            dot.frame = frame;
            dot.image = (i == self.currentPage) ? _imgCurrent : _imgNormal;
        }
    }
}

@end